package pers.cyril.jdb.client.command;

import com.beust.jcommander.IParametersValidator;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import lombok.Data;

import java.util.Map;

/**
 * 说点什么吧
 *
 * @author Wang Cyril
 * @date 2024/5/23 22:56
 */
@Parameters(commandNames = "create", commandDescription = "create database or user", parametersValidators = CreateCommand.Validator.class)
@Data
public class CreateCommand {

    public static class Validator implements IParametersValidator {

        @Override
        public void validate(Map<String, Object> map) throws ParameterException {
            if(map.get("user") != null && map.get("-p") == null && map.get("--password") == null){
                throw new ParameterException("create user need a password eg: create user -p || --password");
            }
        }
    }

    @Parameter(names = {"database"}, description = "create database")
    private String database;

    @Parameter(names = {"user"}, description = "create user")
    private String username;

    @Parameter(names = {"-p", "--password"}, description = "create user with password")
    private String password;
}
